﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace Jenvin.Library.Threading
{
    /// <summary>
    /// 任务执行的上下文。所有的任务，共用 ，注意并发操。
    /// </summary>
    public class TaskContext
    {
        public const int WAITING = 0;
        public const int EXECUTING = 1;
        public const int EXITED = 2;
        /// <summary>
        /// 任务数
        /// </summary>
        internal int m_taskCount = 0;

        /// <summary>
        /// 运行状态
        /// </summary>
        internal int m_status;
        public int TaskCount { get { return m_taskCount; } }
        public int Status { get { return m_status; } }

        public object Params { get; set; }
        public Exception LastError { get; set; }
        /// <summary>
        /// 退出条件 
        /// </summary>
        private volatile bool m_exited = false;
        public bool Exited
        {
            get
            {
                return m_exited;
            }
            set
            {
                m_exited = value;
            }
        }

        internal ManualResetEvent m_waitForExit = new ManualResetEvent(false);
        //internal  m
        public void WaitForExit()
        {
            m_waitForExit.WaitOne();
        }
    }
}
